﻿using Microsoft.EntityFrameworkCore.Migrations;

namespace NFine.EntityFramework.Migrations
{
    public partial class Modified_User_Organize_Position_Nullable : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_sys_user_sys_organize_CompanyId",
                table: "sys_user");

            migrationBuilder.DropForeignKey(
                name: "FK_sys_user_sys_organize_DepartmentId",
                table: "sys_user");

            migrationBuilder.DropForeignKey(
                name: "FK_sys_user_sys_position_PositionId",
                table: "sys_user");

            migrationBuilder.AlterColumn<long>(
                name: "PositionId",
                table: "sys_user",
                nullable: true,
                oldClrType: typeof(long));

            migrationBuilder.AlterColumn<long>(
                name: "DepartmentId",
                table: "sys_user",
                nullable: true,
                oldClrType: typeof(long));

            migrationBuilder.AlterColumn<long>(
                name: "CompanyId",
                table: "sys_user",
                nullable: true,
                oldClrType: typeof(long));

            migrationBuilder.AddForeignKey(
                name: "FK_sys_user_sys_organize_CompanyId",
                table: "sys_user",
                column: "CompanyId",
                principalTable: "sys_organize",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_sys_user_sys_organize_DepartmentId",
                table: "sys_user",
                column: "DepartmentId",
                principalTable: "sys_organize",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_sys_user_sys_position_PositionId",
                table: "sys_user",
                column: "PositionId",
                principalTable: "sys_position",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_sys_user_sys_organize_CompanyId",
                table: "sys_user");

            migrationBuilder.DropForeignKey(
                name: "FK_sys_user_sys_organize_DepartmentId",
                table: "sys_user");

            migrationBuilder.DropForeignKey(
                name: "FK_sys_user_sys_position_PositionId",
                table: "sys_user");

            migrationBuilder.AlterColumn<long>(
                name: "PositionId",
                table: "sys_user",
                nullable: false,
                oldClrType: typeof(long),
                oldNullable: true);

            migrationBuilder.AlterColumn<long>(
                name: "DepartmentId",
                table: "sys_user",
                nullable: false,
                oldClrType: typeof(long),
                oldNullable: true);

            migrationBuilder.AlterColumn<long>(
                name: "CompanyId",
                table: "sys_user",
                nullable: false,
                oldClrType: typeof(long),
                oldNullable: true);

            migrationBuilder.AddForeignKey(
                name: "FK_sys_user_sys_organize_CompanyId",
                table: "sys_user",
                column: "CompanyId",
                principalTable: "sys_organize",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_sys_user_sys_organize_DepartmentId",
                table: "sys_user",
                column: "DepartmentId",
                principalTable: "sys_organize",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_sys_user_sys_position_PositionId",
                table: "sys_user",
                column: "PositionId",
                principalTable: "sys_position",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }
    }
}
